package com.hub.utils;

import com.hub.frame.consts.ConstantUtil;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * TokenUtil
 *
 * @description: token工具类
 * @author hub
 * @create: 2020-05-18 09:47
 */
public class TokenUtil {

    /**
     * 获取请求的token
     */
    public static String getRequestToken(HttpServletRequest httpRequest) {

        //从header中获取token
        String token = httpRequest.getHeader(ConstantUtil.X_ACCESS_TOKEN);
        //如果header中不存在token，则从参数中获取token
        if (StringUtils.isEmpty(token)) {
            token = httpRequest.getParameter(ConstantUtil.X_ACCESS_TOKEN);
        }
        return token;
    }
}
